package com.sanploy.manage.service.impl;

import com.sanploy.common.domain.User;
import com.sanploy.common.domain.vo.Page;
import com.sanploy.manage.mapper.UserMapper;
import com.sanploy.manage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zhu yingzhi on 2017/9/26.
 * @author yingzhi zhu
 * 用户逻辑处理接口实现
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<User> findAllUser(int currentPage, int pageSize) {
        Page<User> page = new Page<>();
        int total = userMapper.countAll(); //查找总数并设置返回的页数，及当前的分页信息
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        page.setTotal(total);
        page.setTotalPage((int)Math.ceil((double)total/(double)pageSize));
        page.setList(userMapper.selectAll((currentPage-1)*pageSize,pageSize));
        return page;
    }
}
